|
Example of using the "OnBeforePrint" event Let us show the aforesaid in practice. Let us create a report, which represents the list of clients. This report will include only those companies, which names begin with the letter "A." Let us create a new project in Delphi, put the "TTable," "TfrxDBDataSet," "TfrxReport" components to the form and set them: Table1: frxDBDataSet1: Enter the report’s editor and create a report of the following type:
Let us extract a data-band and switch to the "Events" bookmark in the objects’ inspector:
To create the "OnBeforePrint" event’s handler (this is exactly what would be most appropriate to us), double-click on the blank field in front of the event’s name:
At the same time, a blank handler is being added to the script’s text, and the designer switches to the "Code" bookmark:
As you can see, everything operates in a similar way as in Delphi environment. The only thing we should do after that is to write the following code in the handler’s body: if Copy( Run the report and make sure, that the script works correctly:
Let us explain several details. You can assign one handler to several events of different objects at once; in this case the "Sender" parameter defines the object, which has initiated the event (similarly to the "Sender" parameter in the Delphi events). To assign a name of the already existing handler to the event, one can either enter it manually in the objects’ inspector, or select it in the pulldown, in exactly the same way as in the Delphi environment:
The link to the handler can be easily deleted. To do that, select a required property and click the "Delete" key. |